from flask_sqlalchemy import SQLAlchemy

# 初始化SQLAlchemy实例
db = SQLAlchemy()

class GroupInfo(db.Model):
    """小组信息模型
    
    Attributes:
        id: 小组ID
        name: 小组名称
        count: 成员数量
    """
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)
    count = db.Column(db.Integer, nullable=False)

    def __repr__(self):
        return f'<Group {self.name}>'


class TeamMember(db.Model):
    """团队成员模型
    
    Attributes:
        id: 成员ID
        name: 成员姓名
        responsibility: 成员职责
        introduction: 成员介绍
    """
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)
    responsibility = db.Column(db.String(200), nullable=False)
    introduction = db.Column(db.Text, nullable=False)

    def to_dict(self):
        return {
            'id': self.id,
            'name': self.name,
            'responsibility': self.responsibility,
            'introduction': self.introduction,
            'photo': f'/static/images/{self.id}.jpg'
        }

# 用户表模型
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(100), unique=True, nullable=False)
    password = db.Column(db.String(200), nullable=False)
    avatar = db.Column(db.String(200), default='default_avatar.png')  # 添加头像字段

    def __repr__(self):
        return f'<User {self.username}>'